package com.sc.thread.volatiletest;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by Shen Chao on 2018-07-03-003.
 */
public class AtomicIntegerTest {
    private AtomicInteger num = new AtomicInteger();

    private void increase() {
        num.getAndIncrement();
    }

    public static void main(String[] args) {
        final AtomicIntegerTest test = new AtomicIntegerTest();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                for (int j = 0; j < 10; j++) {
                    test.increase();
                }
            }).start();
        }
//
//        while (Thread.activeCount() > 1) { //保证前面的线程都执行完
//            Thread.yield();
//        }
        System.out.println(test.num);
    }
}
